﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MINERP.DAL;
using MINERP.COM;
using MINERP.MODEL.Frontier;

namespace MINERP.BLL.Frontier
{
    public class OrderFileBLL
    {
        /// <summary>
        /// 获得订单文件夹列表
        /// </summary>
        /// <param name="orderProductId"></param>
        /// <returns></returns>
        public List<OrderFileModel> GetOrderFileList(int orderProductId)
        {
            List<OrderFileModel> list = new List<OrderFileModel>();
            using (newSampleYPDBEntities entity = new newSampleYPDBEntities())
            {
                List<OrderFile> listOrderFile;
 
                listOrderFile = entity.OrderFile.Where(o=>o.orderInfo.OrderProductId==orderProductId).ToList();
               
                foreach (var item in listOrderFile)
                {
                    int photoNum = 0;
                    OrderFileModel om = new OrderFileModel();
                    om.ConditionFilePath = item.ConditionFilePath;
                    om.CreateTime = item.createTime;
                    om.FolderName = item.FolderName;
                    om.lastPrintTime = item.lastPrintTime;
                    om.OrderFileID = item.OrderFileID;
                    if (!item.orderInfoReference.IsLoaded)
                    {
                        item.orderInfoReference.Load();
                    }
                    om.OrderProductId = item.orderInfo.OrderProductId;
                    if (!item.paperFaceReference.IsLoaded)
                    {
                        item.paperFaceReference.Load();
                    }
                    om.PaperFaceId = item.paperFace.PaperFaceID;
                    om.PaperFaceName = item.paperFace.Name;
                    if (!item.paperTypeReference.IsLoaded)
                    {
                        item.paperTypeReference.Load();
                    }
                    om.PaperTypeId = item.paperType.PaperTypeID;
                    om.PaperTypeName = item.paperType.Name;
                    if (!item.printerReference.IsLoaded)
                    {
                        item.printerReference.Load();
                    }
                    om.PrinterId = item.printer.PrinterID;
                    om.Priority = item.Priority;
                    om.Remark = item.Remark;
                    om.Status = item.Status;
                    om.Width = (double)item.Width;
                    om.Length = (double)item.Length;
                    if (!item.photoInfo.IsLoaded)
                    {
                        item.photoInfo.Load();
                    }

                    foreach (var pho in item.photoInfo)
                    {
                        photoNum += (int)pho.TotalNum;
                    }
                    om.PhotoNum = photoNum;
                    switch (item.Status)
                    {
                        case 0:
                            om.StatusName = "未打印";
                            break;
                        case 1:
                            om.StatusName = "生成错误";
                            break;
                        case 2:
                            om.StatusName = "已修正";
                            break;
                        case 3:
                            om.StatusName = "打印完成";
                            break;
                        default:
                            break;
                    }
                    list.Add(om);

                }
            }
            return list;
        }

        /// <summary>
        /// 获得产品的文件夹数量
        /// </summary>
        /// <param name="orderProductId"></param>
        /// <returns></returns>
        public int GetFolderNum(int orderProductId)
        {
            int num = 0;
            using (newSampleYPDBEntities enty = new newSampleYPDBEntities())
            {
                num = enty.OrderFile.Where(o => o.orderInfo.OrderProductId == orderProductId).ToList().Count;
            }
            return num;
        }
    }
}
